from flask_restful import Resource

from restful.api__.session import login_required_current_user_generate, \
    uid_required_target_user_generate, pid_required_target_post_generate
from restful.model.query import QueryMultipleInstances
from restful.model.tables import Comment
from restful.response import ResponseSuccess

class UserAllCommentsInOnePost(Resource):
    @login_required_current_user_generate
    @uid_required_target_user_generate
    @pid_required_target_post_generate
    def get(self,target_user,target_post,current_user):
        comments = QueryMultipleInstances(Comment,{'uid':target_user.id,'pid':target_post.id})
        return ResponseSuccess(data=[{
                'time':i.time,
                'content':i.content
            } for i in comments]
        )